home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / mldl-1.02 / comp.sys.handhelds_6330_000000.msg next >
Internet Message Format  |  1991-04-30  |  36KB

  1. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!think.com!snorkelwacker.mit.edu!ai-lab!rice-chex!bson
  2. From: bson@rice-chex.ai.mit.edu (Jan Brittenson)
  3. Newsgroups: comp.sys.handhelds
  4. Subject: HP-48 MLDL Version Beta 1.02 (Manual)
  5. Keywords: hp48 internals
  6. Message-ID: <15416@life.ai.mit.edu>
  7. Date: 30 Apr 91 00:11:18 GMT
  8. Sender: news@ai.mit.edu
  9. Organization: nil
  10. Lines: 1149
  11.  
  12. This is the manual part of MLDL version 1.02. Differences from 1.01:
  13.  
  14.     o Breakpoints
  15.  
  16.     o Server mode of operation (i.e. remote control, via wire)
  17.  
  18.     o Key arguments (addresses, etc)
  19.  
  20.     o Improved manual
  21.  
  22.  
  23. Enjoy,
  24.  
  25.  
  26.  O  /
  27.   \/
  28.   /\  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29.  O  \
  30.  
  31.                                     1.
  32.  
  33.  
  34. MLDL 1.02, APRIL 1991
  35. ---------------------
  36.  
  37.  
  38.    The MLDL is a Machine Language Development Library for the HP-48SX,
  39. and as such is primarily intended for HP-48 Machine-Language
  40. Programmers familiar with the following:
  41.  
  42.  
  43.     o  The Saturn instruction set
  44.  
  45.     o  Assembler programming
  46.  
  47.     o  Machine code debugging
  48.  
  49.     o  RPL internals - GC, system RPL, PMC
  50.  
  51.                                     1.
  52.  
  53.  
  54. INSTALLING THE LIBRARY
  55. ----------------------
  56.  
  57.  
  58.    The MLDL consists of five named commands, and has been given the
  59. number 1092 decimal (hexadecimal 444). To install it, transfer the
  60. binary file to your calculator and store it in a suitable port. Turn
  61. the calculator off, then back on, and go to the directory where you
  62. wish to attach it - HOME is fine. Enter :p:1092 where `p' is the port
  63. you stored it in, then ATTACH. To remove it, go to the directory where
  64. you previously attached it, enter `:p:1092', press DUP DETACH, then
  65. PURGE.  The library does not automatically attach.
  66.  
  67. Installation example, assuming I/O has been properly set up:
  68.  
  69.     HOME
  70.     'MLDL' KGET
  71.     MLDL :0:1092 STO
  72.  
  73.     (Turn the calculator OFF, then back ON)
  74.  
  75.     :0:1092 ATTACH
  76.  
  77.  
  78. Removal example:
  79.  
  80.     HOME
  81.     :0:1092 ENTER DUP
  82.     DETACH
  83.     PURGE
  84.  
  85.    The display should briefly flicker as you purge the library from
  86. the port.
  87.  
  88.                                     3.
  89.  
  90.  
  91. LIBRARY COMMANDS
  92. ----------------
  93.  
  94.  
  95. [ABOUTMLDL]
  96.  
  97. Displays version and copyright.
  98.  
  99.  
  100. [MLDB]
  101.  
  102.    Saturn ML Debugger. This description covers the MLDB local mode. It
  103. can also operate in one of two server modes: interactive or protocol,
  104. described under MLDB Server Modes below. In Local Mode, the HP-48
  105. display and keyboard, are used to control the debugger. In Server
  106. Mode, control is maintained via the serial port, either from a dumb
  107. ASCII terminal (Interactive Mode), or a dedicated front-end (Protocol
  108. Mode). To assert that MLDB is in Local Mode when invoked, clear user
  109. flags 32 and 33:
  110.  
  111.  
  112.     32 33 CF CF
  113.  
  114.  
  115.    MLDB allows you single-step ML programs, as well as examine
  116. registers and memory contents. Since it single-steps ML, it is not
  117. useful for debugging RPL code - unless you wish to follow your RPL
  118. thread on an ML level. When invoked, an argument in expected in level 1:
  119.  
  120.  
  121.     Code object
  122.  
  123.             Halts before the first instruction of the code object.
  124.         Both the PC and A registers are set to the address of the
  125.         first instruction.
  126.  
  127.     XLIB
  128.  
  129.            The XLIB must be a code object, which becomes the
  130.         argument.
  131.  
  132.     Binary integer
  133.  
  134.         Treats the binary integer as the address of a prefixed
  135.         machine code routine (PMC). Halts at the first instruction
  136.         of the PMC. PMCs consist of a 5-nybble pointer to the first
  137.         instruction which is usually, but not always, the address
  138.         of the PMC plus 5.
  139.         
  140.     @#3a81 (True)
  141.  
  142.     Any object other than @#3a81
  143.  
  144.         Ignored - the debugger returns immediately. In the
  145.         future, @#3a81 (True) will cause the debugger to use the
  146.         next object in sequence. It will be possible to include a
  147.         call to MLDB and precede it with a test to determine
  148.         whether to actually debug or run free. A user flag test,
  149.         for instance.
  150.  
  151.                                     4.
  152.  
  153.  
  154.    Local Mode MLDB uses PICT (the graphical display) to present
  155. information. Since all information will not fit on one display at
  156. once, it has been divided into 7 screens. Only one screen is active at
  157. any one time. Switching between screens is done by means of the 6 menu
  158. keys, here referred to as A-F, which correspond to screen 1 through 6
  159. respectively, and the MTH key, which corresponds to screen 7.
  160.  
  161.    The sample screens 1-7 below are from the first instruction of the
  162. PMC at #59CC, and can be reasonably reproduced by:
  163.  
  164.  
  165.     #59CC MLDB
  166.  
  167.  
  168.  
  169. Screen 1  - General CPU State (key [A])
  170.  
  171.    Mnemonic............................ |CALL.4 #0679B         |
  172.    Opcode.............................. | 8E4CD0            |
  173.    PC, P, Carry, Hex/Dec mode, ST...... |@:059D1 P:0 CH ST:218 |
  174.    A.A and C.A......................... |A:000CC C:77794       |
  175.    B.A, D.A, and HST................... |B:729A9 D:00F96 HST:2 |
  176.    D0 and 6 bytes @D0.................. |D0:409C1/9540A8240BC9 |
  177.    D1 and 6 bytes @D1.................. |D1:77799/000000000000 |
  178.    Top 3 levels of RSTK................ |RST:00000:00000:00000 |
  179.  
  180.  
  181. Screen 2  - Arithmetic registers (key [B])
  182.  
  183.    Mnemonic............................ |CALL.4 #0679B         |
  184.    Opcode.............................. | 8E4CD0            |
  185.    PC, P, Carry, Hex/Dec mode, ST...... |@:059D1 P:0 CH ST:218 |
  186.    Register A.......................... |A:00000005444000CC    |
  187.    Register B.......................... |B:000000000007611E    |
  188.    Register C.......................... |C:000000000007792C    |
  189.    Register D.......................... |D:00000000000004D0    |
  190.    Top 3 levels of RSTK................ |RST:00000:00000:00000 |
  191.  
  192.  
  193. Screen 3  - Data registers (key [C])
  194.  
  195.    Mnemonic............................ |CALL.4 #0679B         |
  196.    Opcode.............................. | 8E4CD0            |
  197.    PC, P, Carry, Hex/Dec mode, ST...... |@:059D1 P:0 CH ST:218 |
  198.    Register R0......................... |R0:053385D439800040   |
  199.    Register R1......................... |R1:00000005444059D1   |
  200.    Register R2......................... |R2:0000000000075BC1   |
  201.    Register R3......................... |R3:0000000544402E92   |
  202.    Register R4......................... |R4:00015075A6375AA1   |
  203.    Top 3 levels of RSTK................ |RST:00000:00000:00000 |
  204.  
  205.                                     5.
  206.  
  207.  
  208. Screen 4  - Return stack (key [D])
  209.  
  210.    Mnemonic............................ |CALL.4 #0679B         |
  211.    Opcode.............................. | 8E4CD0            |
  212.    PC, P, Carry, Hex/Dec mode, ST...... |@:059D1 P:0 CH ST:218 |
  213.                                         |                |
  214.    RSTK levels 0 and 4................. |RST0:00000 RST4:00000 |
  215.    RSTK levels 1 and 5................. |RST1:00000 RST5:00000 |
  216.    RSTK levels 2 and 6................. |RST2:00000 RST6:00000 |
  217.    RSTK levels 3 and 7................. |RST3:00000 RST7:00000 |
  218.  
  219.  
  220. Screen 5  - Memory dump (key [E])
  221.  
  222.    Locations 59A0-59AF................. |059A0:56113680913420CC|
  223.    Locations 59B0-59BF................. |059B0:4E0156716FCC56FD|
  224.    Locations 59C0-59CF................. |059C0:015B38D5E0101D95|
  225.    Locations 59D0-59DF................. |059D0:08E4CD08E46C0101|
  226.    Locations 59E0-59EF................. |059E0:D230574911191443|
  227.    Locations 59F0-59FF................. |059F0:4E4A201101311456|
  228.    Locations 5A00-5A0F................. |05A00:12280A50143174E7|
  229.    Locations 5A10-5A1F................. |05A10:8E58D01311741431|
  230.  
  231.    The current location is indicated by an inverse digit.
  232.  
  233.  
  234. Screen 6  - ML Instruction Stream (key [F])
  235.  
  236.    PC, P, Carry, Hex/Dec mode, ST...... |@:059D1 P:0 CH ST:218 |
  237.    Next 7 instructions................. |#CALL.4##0679B########|
  238.                                         | CALL.4 #06641           |
  239.                                         | MOVE.W A,R1           |
  240.                                         | CLR.A C           |
  241.                                         | MOVE.P1 #5,C           |
  242.                                         | CALL.3 #05B7D           |
  243.                                         | MOVE.W R1,C           |
  244.  
  245.  
  246.       The next instruction is the one displayed in reverse. Currently,
  247.    it will always appear at the top. (Here somewhat crudely
  248.    illustrated with the # signs.)
  249.  
  250.  
  251. Screen 7  - Breakpoint Table Screen (key MTH)
  252.  
  253.    Breakpoint #1....................... | 1:6100 +02           |
  254.    Breakpoint #2....................... | 2:6104 -02           |
  255.    Breakpoint #3....................... | 3:613A  00           |
  256.    Breakpoints #4-#8: not used......... | 4:0000  00           |
  257.                                     | 5:0000  00           |
  258.                                     | 6:0000  00           |
  259.                                     | 7:0000  00           |
  260.                                     | 8:0000  00           |
  261.  
  262.    Any breakpoints at the current location are displayed in reverse.
  263.  
  264.                                     6.
  265.  
  266.  
  267. The Local Mode MLDB keyboard
  268. ----------------------------
  269.  
  270.    A number of keys will accept an argument, referred to as ARG. To
  271. enter ARG, press [0] (the zero key) followed by a hex integer, which
  272. will make up ARG. It is restricted to 5 hex digits (20 bits). As [0]
  273. is pressed, the bottom display line, regardless of screen currently
  274. active, becomes an ARG entry line:
  275.  
  276.     |ARG:00000             |
  277.  
  278.    This reformat remains in effect until a non-hex key is pressed, at
  279. which point that key is passed ARG. Some keys behave differently
  280. depending on whether ARG was present - [DEL], for instance, does
  281. nothing, effectively cancelling ARG. The backarrow, [<==], divides the
  282. argument by 16, in effect shifting it right one digit. The argument is
  283. always a 20-bit unsigned integer. The digits A-F are found on the menu
  284. keys.  The [+/-] key negates (2's complement) the argument.
  285.  
  286.  
  287. Example, ARG entry:
  288.  
  289.     Keys        Comments    Bottom line following keys
  290.  
  291.     0        Start entry    |ARG:00000             |
  292.     5        Digit 5        |ARG:00005             |
  293.     7        Digit 7        |ARG:00057             |
  294.     [<==]        Shift right    |ARG:00005             |
  295.     9        Digit 9        |ARG:00059             |
  296.     D1        Digits D, 1    |ARG:059D1             |
  297.     [+/-]        Negate        |ARG:FA62F             |
  298.     000        Three 0s    |ARG:2F000             |
  299.     [<==]        Shift right    |ARG:02F00             |
  300.     [DEL]        Cancel ARG
  301.  
  302.  
  303.                                     7.
  304.  
  305.  
  306.    Moving about is done with the arrow keys and the NXT key - notice
  307. that none of these keys actually execute the previous instruction,
  308. only the PC is affected:
  309.  
  310.     [up]    Decrement PC by 16 (or 16*ARG)
  311.     [down]    Increment PC by 16 (or 16*ARG)
  312.     [left]    Decrement PC by 1 (or ARG)
  313.     [right]    Increment PC by 1 (or ARG)
  314.     [NXT]    Move to next instruction (or ARG instructions forward)
  315.  
  316.  
  317. In addition, there is a mark:
  318.  
  319.     [x]    (Mulitplication key)
  320.         Set mark to ARG, if present. Otherwise the MARK
  321.         is set to the current PC.
  322.  
  323.     [+/-]    Swaps the PC and the mark.
  324.  
  325.  
  326.  
  327. Example, Moving About:
  328.  
  329.     Keys        Comments    Display following keys
  330.  
  331.     059D1[ENTER]    PC=#059D1h    |@:059D1 P:0 CH ST:218 |    
  332.                     |#CALL.4##0679B########|
  333.                     | CALL.4 #06641        |
  334.                     | MOVE.W A,R1          |
  335.                     | CLR.A C              |
  336.                     | MOVE.P1 #5,C         |
  337.                     | CALL.3 #05B7D        |
  338.                     | MOVE.W R1,C          |
  339.  
  340.  
  341.     04[right]    PC=PC+4        |@:059D5 P:0 CH ST:218 |
  342.                     |#CLR.A#A##############|
  343.                     | CALL.4 #06641        |
  344.                     | MOVE.W A,R1          |
  345.                     | CLR.A C              |
  346.                     | MOVE.P1 #5,C         |
  347.                     | CALL.3 #05B7D        |
  348.                     | MOVE.W R1,C          |
  349.  
  350.  
  351.     059D1[ENTER]    PC=#059D1    |059A0:56113680913420CC|
  352.     [E]        Memory dump,    |059B0:4E0156716FCC56FD|
  353.             screen 5    |059C0:015B38D5E0101D95|
  354.                     |059D0:0#E4CD08E46C0101|
  355.                     |059E0:D230574911191443|
  356.                     |059F0:4E4A201101311456|
  357.                     |05A00:12280A50143174E7|
  358.                     |05A10:8E58D01311741431|
  359.  
  360.                                     8.
  361.  
  362.  
  363.     [up]        PC=PC-#10h    |05990:3A6E80D0F40D4F01|
  364.                     |059A0:56113680913420CC|
  365.                     |059B0:4E0156716FCC56FD|
  366.                     |059C0:0#5B38D5E0101D95|
  367.                     |059D0:08E4CD08E46C0101|
  368.                     |059E0:D230574911191443|
  369.                     |059F0:4E4A201101311456|
  370.                     |05A00:12280A50143174E7|
  371.  
  372.  
  373.     059D1[ENTER]    Back to #59D1h    |@:059D1 P:0 CH ST:218 |
  374.     [F]        ML instructions    |#CALL.4##679B#########|
  375.                     | CALL.4 #06641        |
  376.                     | MOVE.W A,R1          |
  377.                     | CLR.A C              |
  378.                     | MOVE.P1 #5,C         |
  379.                     | CALL.3 #05B7D        |
  380.                     | MOVE.W R1,C          |
  381.  
  382.  
  383.     [NXT]        Forward one    |@:059D7 P:0 CH ST:218 |
  384.             instruction    |#CALL.4##06641########|
  385.                     | MOVE.W A,R1          |
  386.                     | CLR.A C              |
  387.                     | MOVE.P1 #5,C         |
  388.                     | CALL.3 #05B7D        |
  389.                     | MOVE.W R1,C          |
  390.                     | MOVE.A C,@D0           |
  391.  
  392.  
  393.     [x]        Set mark    |@:059D7 P:0 CH ST:218 |
  394.     03[NXT]        Forward 3    |#MOVE.P1##5,C#########|
  395.             instructions    | CALL.3 #05B7D        |
  396.                     | MOVE.W R1,C          |
  397.                     | MOVE.A C,@D0         |
  398.                     | MOVE.P5 #02A4E,C     |
  399.                     | MOVE.W R0,A          |
  400.                     | MOVE.A A,D1          |
  401.  
  402.  
  403.     [+/-]        Toggle mark,    |@:059D7 P:0 CH ST:218 |
  404.             PC        |#CALL.4##06641########|
  405.                     | MOVE.W A,R1          |
  406.                     | CLR.A C              |
  407.                     | MOVE.P1 #5,C         |
  408.                     | CALL.3 #05B7D        |
  409.                     | MOVE.W R1,C          |
  410.                     | MOVE.A C,@D0         |
  411.  
  412.  
  413.    The arrow keys are most useful for moving around in the memory
  414. dump, but can also be used to arbitrarily increment and decrement the
  415. PC to shift the instruction stream by single nybbles. The mark
  416. commands are useful for temporarily remembering an address.
  417.  
  418.                                     8.
  419.  
  420.  
  421.    There are three ways of aborting your program, and seubsequently
  422. leaving the debugger:
  423.  
  424.     [<==]    (Delete key)
  425.         Exits.
  426.  
  427.     [DEL]    Restores system registers to the state they were in
  428.         when the debugger was entered. This is useful if you
  429.         would need to exit in the middle of your program and
  430.         the system registers contain random data. It does
  431.         nothing if ARG was supplied, in effect acting as an
  432.         ARG cancellation key.
  433.  
  434.     [1/X] [1/X]
  435.         Panic exit. If you know the machine will crash when
  436.         you exit, such as could be the case if memory has been
  437.         reconfigured. Resets the calculator, which causes the
  438.         MLDL to become detached. Follow the procedure
  439.         described in the first section of this document to
  440.         reattach.
  441.         
  442.  
  443. Four keys are used to execute your program:
  444.  
  445.  
  446.     [+]    Single-steps one (or ARG) instruction(s), pointed to
  447.         by the PC. Follows CALLs. If ARG, then also checks for
  448.         breakpoints.
  449.  
  450.     [-]    Same as [+], but does not follows CALLs; instead, the
  451.         program halts when it returns from the CALL.
  452.  
  453.     [.]    Redraws the display but otherwise does nothing.
  454.  
  455.     [EVAL]    Continue execution, run until program completes,
  456.         breakpoint is reached, or [-] CALL execution
  457.         completes.
  458.  
  459.                                     9.
  460.  
  461.  
  462.    The MLDB maintains a breakpoint table of eight slots. Each slot
  463. consists of an address and a counter, both of which are displayed when
  464. the MTH key is pressed (see below). The address is 20 bits and the
  465. counter is eight bits. In addition, each slot holds the breakpoint
  466. instruction (a CALL instruction) to be inserted into the program when
  467. running it. Breakpoints only work in RAM, although they can be set in
  468. ROM and triggered by multi-instruction single-steps. When a breakpoint
  469. is triggered, its counter is incremented; if after the increment it is
  470. negative (80-FF), the program will continue. Setting a negative
  471. counter is therefore a way of instruction MLDB to "ignore this
  472. breakpoint N times" where N is in the range 01-7F hexadecimal. If the
  473. counter is positive, the program is halted. Positive counters indicate
  474. how many times the program has halted at a specific breakpoint.
  475.  
  476.  
  477. Example, Program Completion:
  478.  
  479.        Start with the stack display, HEX mode, in the MLDL library
  480.     menu. Only the relevant lines of the stack display are
  481.     included in the example below. #3244h is DROP.
  482.  
  483.                     
  484.     Keys        Comments    Display following keys
  485.  
  486.     HEX STD        Set up modes
  487.  
  488.  
  489.     2 1 #3244    Enter two    |3:                   2|
  490.     [ENTER]        arguments for    |2:                   1|
  491.             DROP, and the    |1:             # 3244h|
  492.             of the DROP 
  493.             PMC
  494.  
  495.  
  496.     [MLDB]        Invoke MLDB on  |@:03249 P:0  H ST:218 |
  497.     [F]        the DROP PMC    |#ADD.A##5,D1##########|
  498.             and choose the    | INC.A D              |
  499.             instruction    | MOVE.A @D0,A         |
  500.             screen        | ADD.A #5,D0          |
  501.                     | JUMP.A @A            |
  502.                     | MOVE.A C,B           |
  503.                     | MOVE.1 #3,P          |
  504.  
  505.  
  506.        The DROP PMC consists of only the first 5 instructions.
  507.     The JUMP @A will cause the program to reach completion.
  508.  
  509.  
  510.     [EVAL]        Allow program    |1:                   2|
  511.             to run freely
  512.  
  513.  
  514.                                     10.
  515.  
  516.  
  517. Breakpoints are accessible via three keys:
  518.  
  519.  
  520.     [MTH]    Switch to breakpoint table screen. Any entry at the
  521.         current PC will be displayed in reverse video.
  522.  
  523.     [PRG]    Set breakpoint. Waits for a further key, 1-8, which
  524.         specifies the breakpoint to set. ARG is the address
  525.         the breakpoint is set to. If no ARG is entered, then
  526.         the breakpoint is cleared (its address and counter are
  527.         set to 00000 and 00, respectively).
  528.  
  529.     [STO]    Set breakpoint counter. Waits for a further key, 1-8,
  530.         which specifies the breakpoint whose counter is to be
  531.         set. ARG is the new counter value. The counter is
  532.         cleared if no ARG is entered. Only the low 8 bits of
  533.         ARG are used.
  534.  
  535.  
  536.    Example, Breakpoints. For an illustration on how to enter ARG, see
  537. the "ARG entry" example above.
  538.  
  539.  
  540.     Keys        Comments    Display following keys
  541.  
  542.     059D1[ENTER]    PC=59D1        |CALL.4 #0679B         |
  543.     [A]        Screen 1    | 8E4CD0               |
  544.                     |@:059D1 P:0 CH ST:218 |
  545.                     |A:000CC C:77794       |
  546.                     |B:729A9 D:00F96 HST:2 |
  547.                     |D0:409C1/9540A8240BC9 |
  548.                     |D1:77799/000000000000 |
  549.                     |RST:00000:00000:00000 |
  550.  
  551.  
  552.     [MTH]        Breakpoint    | 1:00000  00           |
  553.             table screen    | 2:00000  00           |
  554.                     | 3:00000  00           |
  555.                     | 4:00000  00           |
  556.                     | 5:00000  00           |
  557.                     | 6:00000  00           |
  558.                     | 7:00000  00           |
  559.                     | 8:00000  00           |
  560.  
  561.  
  562.     059D1[PRG]1    Set        |#1:059D1##00##########|
  563.             breakpoint 1    | 2:00000  00           |
  564.             at #59D1h    | 3:00000  00           |
  565.                     | 4:00000  00           |
  566.                     | 5:00000  00           |
  567.                     | 6:00000  00           |
  568.                     | 7:00000  00           |
  569.                     | 8:00000  00           |
  570.  
  571.  
  572.        The inverse bar in the display above indicates that the
  573.     breakpoint is set at the current PC.
  574.  
  575.                                     11.
  576.  
  577.  
  578.     [F]        Examine    next    |@:059D1 P:0 CH ST:218 |
  579.             7 instructions    | CALL.4 #0679B           |
  580.                     | CALL.4 #06641           |
  581.                     | MOVE.W A,R1           |
  582.                     | CLR.A C           |
  583.                     | MOVE.P1 #5,C           |
  584.                     | CALL.3 #05B7D           |
  585.                     | MOVE.W R1,C           |
  586.  
  587.  
  588.     [MTH]        Back to breakpoint
  589.             table screen
  590.  
  591.     06641[PRG]5    Set        |#1:059D1##00##########|
  592.             breakpoint 5    | 2:00000  00           |
  593.             at #6641h    | 3:00000  00           |
  594.                     | 4:00000  00           |
  595.                     | 5:06641  00           |
  596.                     | 6:00000  00           |
  597.                     | 7:00000  00           |
  598.                     | 8:00000  00           |
  599.  
  600.  
  601.     040[+]        Single-step 64    | 1:059D1  00          |
  602.             instructions    | 2:00000  00          |
  603.                     | 3:00000  00          |
  604.                     | 4:00000  00          |
  605.                     |#5:06641#+01##########|
  606.                     | 6:00000  00          |
  607.                     | 7:00000  00          |
  608.                     | 8:00000  00          |
  609.  
  610.  
  611.        We never really got as far as 64 instructions. Instead we
  612.     ran into the breakpoint at #6641h and stopped there. The
  613.     breakpoint table above tells us why we stopped, and that it is
  614.     our first stop here. Setting breakpoints and single-stepping a
  615.     large number of instructions is the only way to use
  616.     breakpoints in ROM.
  617.  
  618.  
  619.     [STO]5        Clear counter    | 1:059D1  00          |
  620.             of breakpoint 5    | 2:00000  00          |
  621.                     | 3:00000  00          |
  622.                     | 4:00000  00          |
  623.                     |#5:06641##00##########|
  624.                     | 6:00000  00          |
  625.                     | 7:00000  00          |
  626.                     | 8:00000  00          |
  627.  
  628.  
  629.                                     12.
  630.  
  631.  
  632.    A breakpoint is a CALL.A to an entry in the MLDB. When the
  633. breakpoint is reached, control is transfered to the breakpoint trap
  634. handler in the MLDB. It finds the location of the breakpoint on the
  635. return stack (RSTK), looks it up in the breakpoint table, and proceeds
  636. as outlined above. The CALL.A instruction uses 7 nybbles of memory.
  637. Therefore, problems can arise when the program contains a sequence
  638. like this:
  639.  
  640.  
  641.     point:    brcc    foo        ; 3 nybbles
  642.         inc.a    c        ; 2 nybbles
  643.     foo:    inc.a    c        ; 2 nybbles
  644.         dec.a    a        ; 2 nybbles
  645.  
  646.  
  647.    Picture what would happen if a breakpoint is set at `point.' It
  648. uses up 7 nybbles of memory, and thus overwrites the BRCC, subsequent
  649. INC, and the INC at `foo.' Assume another piece of the program makes a
  650. jump to `foo.' This will result in a jump into the last two nybbles of
  651. the breakpoint instruction! The program is bound to break - if we're
  652. lucky this means mysterious results - if we're unlucky, we're going
  653. down in flames (metaphorically speaking).
  654.  
  655.    During a [+] single-step of multiple instructions (actually, any
  656. single-step with an ARG will do), the breakpoints are never inserted
  657. into the program. Instead, each consecutive PC is matched against the
  658. breakpoint table, and if a breakpoint is set at exactly that address,
  659. the single-stepping will stop. This usage of breakpoints is entirely
  660. safe and works under all conditions. It can, of course, be used for
  661. ROM as well as RAM programs. The drawback is execution speed, although
  662. the [-] stepping variant is usually faster than the [+] variant.
  663. Graphics and other CPU-heavy applications take seemingly forever to
  664. run. There is no simple solution - you must take the 7-nybble limit
  665. into consideration when writing such programs. Insert NOPs at places
  666. where you know you will want to insert breakpoints.
  667.  
  668.    The [-] single-step does not follow CALLs. It leaves control to the
  669. subroutine called and lets it run freely until it returns to the
  670. caller, which is the MLDB. It then proceeds with the next instruction
  671. in sequence, the one following the CALL. Time-consuming functions like
  672. graphics routines can be placed in separately debugged and verified
  673. subroutines, and the main program calling these routines debugged with
  674. [-]. This will generally give acceptably quick response.
  675.  
  676. When during [-] step single-a subroutine that is allowed to run free until
  677. it returns, encounters a breakpoint, the program halts. The return
  678. address _into_MLDB_ will be on top of the return stack. Pressing
  679. [EVAL] to continue at this point will cause the subroutine to continue
  680. running free, until it again reaches a breakpoint, or returns, at
  681. which point it returns to MLDB and continues its [-] single-step. The
  682. subroutine can also be single-stepped when it has run into a
  683. breakpoint.
  684.  
  685.                                     13.
  686.  
  687.  
  688. MLDB Server Modes
  689. -----------------
  690.  
  691. User flags 32 and 33 control the MLDB mode:
  692.  
  693.  
  694.               Server,     Server,
  695.         Local    Interactive    Protocol
  696.     ------------------------------------------
  697.       32    Clear        Set           Set
  698.       33    Clear       Clear       Set
  699.  
  700.  
  701.    The normal mode of operation, as described in the previous
  702. sections, is Local mode. The other two modes are referred to as Server
  703. Modes, and are the Interactive Mode - commands (see Server Commands,
  704. below) are entered on a dumb ASCII terminal or emulator, with full
  705. editing (see Server Command Entry, below) - and Protocol Mode, in
  706. which the same commands are accepted as in Interactive Mode, except no
  707. prompts are printed and commands are not echoed during reception. The
  708. Protocol Mode is intended for specialized MLDL Server Front-End
  709. Software (FES) - refer to the manual of the Server FES in question for
  710. details.
  711.  
  712.                                     14.
  713.  
  714.  
  715. Server Mode Commands
  716. --------------------
  717.  
  718.    Commands can be entered in response to the ``*'' prompt in
  719. Interactive Mode, or whenever suitable - they will be processed
  720. sequentially - when in Protocol Mode. Generally, excessive input is
  721. ignored, as are unrecognized commands or commands with invalid
  722. arguments. Commands of up to 40 characters can be entered.
  723.  
  724.  
  725.  
  726.     = <addr>    Set the PC to <addr>.
  727.             <addr> is in the range 00000-FFFFF.
  728.  
  729.     + <offs>    Add <offs> to PC.
  730.             <offs> is in the range 00000-FFFFF.
  731.  
  732.     - <offs>    Subtract <offs> from PC.
  733.             <offs> is in the range 00000-FFFFF.
  734.  
  735.     n [<n>]        Advance PC forward <n> instructions. If no <n>
  736.             is supplied, the PC is advanced one
  737.             instruction.
  738.  
  739.     s [<n>]        Single-step <n> instructions. Same as the [+]
  740.             key in Local Mode. If no <n> is entered, one
  741.             instruction is stepped.
  742.  
  743.     S [<n>]        Single-step <n> instrutions, but don't follow
  744.             CALLs. Same as the [-] key in Local Mode. If
  745.             no <n> is entered, one instruction or CALL is
  746.             is stepped.
  747.  
  748.     c        Continue free-run execution until the program
  749.             completes or a breakpoint is encountered. When
  750.             the program completes, ``Exit'' is printed and
  751.             MLDB exits.
  752.  
  753.     t        Terminate. Exit with current registers.
  754.  
  755.     T        Terminate. Exit with system registers set up
  756.             exactly like when MLDB was first invoked.
  757.  
  758.     R        Reset.
  759.  
  760.     r        Print registers. The HEX/DEC mode is printed
  761.             as ``HD:0'' or ``HD:1''. A zero means that HEX
  762.             mode is active, a one means that DEC mode is
  763.             active.
  764.  
  765.     i [<n>] [<addr>]
  766.             Print instructions. <n> instructions are
  767.             printed, starting at <addr>. The first
  768.             argument is always <n> and the second is
  769.             <addr>. If no <addr> is entered, the current
  770.             PC is assumed. If <n> isn't entered, one - the
  771.             next - instruction is printed. <n> and <addr>
  772.             are both in the range 00000-FFFFF.
  773.  
  774.                                     15.
  775.  
  776.  
  777.     x [<n>] [<addr>]
  778.             Print memory contents. <n> words of 16 nybbles
  779.             are printed, starting at <addr>, each on a
  780.             separate line. The first argument is always
  781.             <n> and the second is <addr>. If no <addr> is
  782.             entered, the current PC is assumed. If <n>
  783.             isn't entered, one - the next - word is
  784.             printed. <n> and <addr> are both in the range
  785.             00000-FFFFF.
  786.  
  787.     z        Print the return stack - the RSTK.
  788.  
  789.     db <n> [<addr>]    Set breakpoint <n> at <addr>.  If <addr> is
  790.             absent, the breakpoint is cleared. <addr> is
  791.             in the range 00000-FFFFF. <n> must be in the
  792.             range 1-8.
  793.  
  794.     hb <n> [<cntr>]    Set breakpoint <n> counter to <cntr>. If
  795.             <cntr> is absent, the counter is set to 00.
  796.             <cntr> is in the range 00-FF. <n> must be in
  797.             the range 1-8.
  798.             
  799.     lb        List breakpoints.
  800.  
  801.  
  802.                                     16.
  803.  
  804.  
  805. Server Command Entry
  806. --------------------
  807.  
  808.    In both Interactive and Protocol Modes, input can be edited,
  809. although no echo or response can be detected in Protocol Mode. The
  810. following table may be of help when you try to locate the editing keys
  811. on your keyboard:
  812.  
  813.  
  814.  
  815.     Backspace, Delete,     Erase the last character entered.
  816.     or Rubout
  817.  
  818.     Control-W        Erase the last word entered.
  819.  
  820.     Control-U or        Erase entire line.
  821.     Control-X
  822.  
  823.     Control-R        Rewrite input.
  824.  
  825.     Return, Enter, or    Execute command entered.
  826.     Control-M
  827.  
  828.  
  829.                                     17.
  830.  
  831.  
  832. Exampe, An Interactive Mode Session
  833. -----------------------------------
  834.  
  835.    We invoke MLDB with #3223, the address of the SWAP PMC. We pass two
  836. arguments to SWAP - 1 and 2. First, we are greeted with a header.
  837.  
  838.     MLDL 1.02
  839.     Copyright (c) 1991 Jan Brittenson
  840.     
  841. Let's first take a look at the SWAP PMC:
  842.  
  843.     * i 9
  844.     MOVE.A @D1,C
  845.     ADD.A #5,D1
  846.     MOVE.A @D1,A
  847.     MOVE.A C,@D1
  848.     SUB.A #5,D1
  849.     MOVE.A A,@D1
  850.     MOVE.A @D0,A
  851.     ADD.A #5,D0
  852.     JUMP.A @A
  853.  
  854. Then the registers:
  855.  
  856.     * r
  857.     CY:0
  858.     P:0
  859.     PC:03228
  860.     A:0000000644403223
  861.     B:0960000000074FB3
  862.     C:0000000000075FBB
  863.     D:0000000000000335
  864.     R0:000000000007BCA5
  865.     R1:0000000644403228
  866.     R2:00000000000505C6
  867.     R3:0000000644400001
  868.     R4:00015074EE274F20
  869.     D0:7C1A5
  870.     D1:75FC0
  871.     ST:000
  872.     HST:2
  873.     HD:0
  874.  
  875. So stack level 1 is at 75FC0.
  876.  
  877.     * x 1 75fc0
  878.     75FC0:ED2A29C2A2000000
  879.  
  880. Which is object 2A2DE.
  881.  
  882.     * x 2 2a2de
  883.     2A2DE:3392000000000000
  884.     2A2EE:0002033920000000
  885.  
  886.    Which is a real (type prefix 2933), the constant 2. Let's step a
  887. few instructions.
  888.  
  889.                                     18.
  890.  
  891.  
  892.     * i
  893.     MOVE.A @D1,C
  894.     * s
  895.     * i
  896.     ADD.A #5,D1
  897.     * s
  898.     * i
  899.     MOVE.A @D1,A
  900.     * s
  901.     * i
  902.     MOVE.A C,@D1
  903.     * s
  904.     * i
  905.     SUB.A #5,D1
  906.     * s
  907.     * i
  908.     MOVE.A A,@D1
  909.     * s
  910.  
  911. Now, what do we have left?
  912.  
  913.     * i 3
  914.     MOVE.A @D0,A
  915.     ADD.A #5,D0
  916.     JUMP.A @A
  917.  
  918.    We step a goodly chunk of instructions. That way we can be sure
  919. that the program completes.
  920.  
  921.     * s 100
  922.     Exit
  923.  
  924.    We're done. The HP-48 stack now reads "2" in level 2, and "1" in
  925. level 1.
  926.  
  927.  
  928.                                     19.
  929.  
  930.  
  931. Some system considerations
  932. --------------------------
  933.  
  934.    The debugger has been designed explicitly so that it will not alter
  935. any static system data or depend on the precise machine configuration.
  936. The only system data it modifies is the keyboard buffer, since it
  937. relies on the system to respond to the keyboard interrupt and manage
  938. the buffer.  Testing has shown that interfering with this results in
  939. poor reliability. Still, there are two instructions the debugger will
  940. refuse to single-step:
  941.  
  942.  
  943.     RESET    
  944.         The effect of this would be the same as ON-C.
  945.  
  946.     CLRB #F,ST
  947.         Executing this instruction would lock up your calculator
  948.         since it would disable all I/O most notably the keyboard.
  949.  
  950.  
  951.    Apart from the aspects outlined above and some system RPL code to
  952. do argument type checking, the debugger is self-contained.
  953.  
  954.                                     20.
  955.  
  956.  
  957. A word of caution
  958. -----------------
  959.  
  960.    The [-] key lets you complete an entire CALL. But beware: the
  961. return stack is replaced by one that will cause the called routine to
  962. return to the debugger. Therefore the routine called cannot rely on
  963. specific return stack contents, or remove return addresses from the
  964. stack, either of which will invariably result in a system crash.
  965. Fortunately, this appears not to be standard practice in the HP-48
  966. ROM.
  967.  
  968.    Despite the effort put into avoiding system collisions, the HP-48
  969. will still remain a largely unprotected system where the debugger - or
  970. other parts of the MLDL - can still be overwritten, which may result
  971. in memory loss. Since the MLDL is stored as a library in a port, it is
  972. not susceptible to general memory allocation, such as dynamic memory
  973. allocation or system display GROB allocations.  On the other hand,
  974. storing another library in the same port may cause it to move -
  975. extreme caution is therefore advisable when single-stepping PMC that
  976. alters stored port data. If you are stepping a port store block copy
  977. by means of either [+] or [-], then the MLDL may be overwritten. If
  978. you're using [-] to call a block copy routine within a similar
  979. context, then the library may have moved and the subsequent return
  980. will cause a system crash and possibly memory corruption.
  981.  
  982.    Single-stepping a machine code program is in no way less dangerous
  983. than allowing it to run uncontrolled. It merely gives you some control
  984. over what happens between instructions. It can even be more dangerous;
  985. hardware may break if left in certain configurations for a period of
  986. time, which may be a fraction of a second. So if you are going to
  987. single-step parts of the system ROM, you should be aware of this risk.
  988. In no way will the author or distributors of the MLDL accept any
  989. responsibility or liability for such damage, regardless of its nature
  990. and extent.
  991.  
  992.    The MLDL is distributed in the hope that it will be useful, but
  993. WITHOUT ANY WARRANTY; without even the implied warranty of
  994. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  995.  
  996.                                     21.
  997.  
  998.  
  999. [MLPR]
  1000.  
  1001.    Disassembles and prints ML programs. Accepts the same arguments as
  1002. MLDB, except @#3a81 and #3ac0 which are not recognized. The program is
  1003. printed to the current print device - IR or Serial. In case of
  1004. problems, first check your PRTPAR - see pages 602-611 in your Owner's
  1005. Manual Volume II. Page 611 explicitly describes the PRTPAR. Each line
  1006. consists of a mnemonic preceded by the address. No opcode is included,
  1007. since it normally is of low interest. Use ML1 (described below) to
  1008. build your own custom disassembler.
  1009.  
  1010.  
  1011.  
  1012. [ML1]
  1013.  
  1014.    Disassembles one ML instruction; allows you to build your own
  1015. disassemblers with special-purpose user interfaces. It takes a binary
  1016. integer in level one, and returns two values; in level 2 the mnemonic
  1017. form preceded by the address, and in level one the address of the next
  1018. instruction. Thus it is a simple task to make a number of consequtive
  1019. calls to ML1. MLOPC can be used to extract the opcode as a string of
  1020. hexadecimal digits. Extract The mnemonic from the string is trivial,
  1021. since it will always be of the form:
  1022.  
  1023.     "xxxxx: m"
  1024.  
  1025. where xxxxx is a five-digit address followed by a colon and a blank.
  1026. The last part of the string, m, is the mnemonic.
  1027.  
  1028.  
  1029. [MLOPC]
  1030.  
  1031.    Returns opcode as a string of hexadecimal digits. Expects two
  1032. binary integers - the first address in level 2 and the final address
  1033. plus one in level 1. Useful for creating the opcode field in a custom
  1034. disassembler. Example, MLOPC:
  1035.  
  1036.     #59D1 #59D7 MLOPC  -->  "8E4CD0"
  1037.  
  1038. The opcode size is limited to 255 digits.
  1039.  
  1040.                                     22.
  1041.  
  1042.  
  1043. MLDL COMMAND SUMMARY
  1044. --------------------
  1045.  
  1046.  
  1047. |-----------------------------------------------------------------------|
  1048. |                                    |
  1049. | Version    Returns version and copyright strings            |
  1050. |                                    |
  1051. |                --> "version" "copyright"        |
  1052. |                                    |
  1053. |-----------------------------------------------------------------------|
  1054. |                                    |
  1055. | MLDB        Saturn Machine Language Debugger            |
  1056. |                                    |
  1057. |            obj    --> any1 ... anyN            |
  1058. |                                    |
  1059. |-----------------------------------------------------------------------|
  1060. |                                    |
  1061. | MLPR        Print Machine Language Program                |
  1062. |                                    |
  1063. |            obj    --> obj                    |
  1064. |                                    |
  1065. |-----------------------------------------------------------------------|
  1066. |                                    |
  1067. | ML1        Single-Instruction Machine Language Disassembler    |
  1068. |                                    |
  1069. |              #address    --> "instruction" #next            |
  1070. |                                    |
  1071. |-----------------------------------------------------------------------|
  1072. |                                    |
  1073. | MLOPC        Machine Language Instruction Opcode            |
  1074. |                                    |
  1075. |       #address1 #address2    --> "hex digits"            |
  1076. |                                    |
  1077. |-----------------------------------------------------------------------+
  1078.  
  1079.                                     23.
  1080.  
  1081.  
  1082. MLDB LOCAL MODE KEYBOARD SUMMARY
  1083. --------------------------------
  1084.  
  1085.     Screens        No ARG            ARG
  1086.  
  1087.     [A]        General CPU State
  1088.     [B]        Arithmetic registers
  1089.     [C]        Data registers
  1090.     [D]        Return stack (RSTK)
  1091.     [E]        Memory dump
  1092.     [F]        Instruction stream
  1093.     [MTH]        Breakpoint table    Breakpoint table
  1094.  
  1095.     ARG entry
  1096.  
  1097.     [0]        Begins ARG entry
  1098.     0-9, A-F    Hex digits
  1099.     [+/-]        2's complement
  1100.     [<==]        Shift right one digit
  1101.     [DEL]        Cancel
  1102.  
  1103.     Moving around
  1104.  
  1105.     [ENTER]        Ignored            PC=ARG
  1106.     [left]        PC=PC-1            PC=PC-ARG
  1107.     [right]        PC=PC+1            PC=PC+ARG
  1108.     [up]        PC=PC-16        PC=PC-16*ARG
  1109.     [down]        PC=PC+16        PC=PC+16*ARG
  1110.     [x]        MARK=PC            MARK=ARG
  1111.     [+/-]        MARK <-> PC        MARK <-> PC
  1112.     [NXT]        Advance one         Advance ARG instructions
  1113.             instruction
  1114.  
  1115.     Breakpoints (b = 1 - 8)
  1116.  
  1117.     [MTH]        Breakpoint table     Breakpoint table screen
  1118.             screen
  1119.     [PRG]b        Clear breakpoint b    Set breakpoint b at ARG
  1120.     [STO]b        Clear breakpoint b    Set breakpoint b counter
  1121.             counter            to ARG
  1122.  
  1123.     Program execution
  1124.  
  1125.     [+]        Single-step one        Single-step ARG instructions
  1126.             instruction
  1127.     [-]        Single-step one        Single-step ARG instructions,
  1128.             instruction, do        do not follow CALLs.
  1129.             not follow CALLs
  1130.     [EVAL]        Let program run until    Ignored
  1131.             completed, or until
  1132.             breakpoint
  1133.  
  1134.                                     24.
  1135.  
  1136.  
  1137. MLDL XLIB TABLE
  1138. ---------------
  1139.  
  1140.    The command numbers are subject to change at random and without
  1141. prior notice. The library number is 444 hexadecimal, which is 1092
  1142. decimal.
  1143.  
  1144.  
  1145.     Command        Number
  1146.     ----------------------
  1147.     Version        1092 0
  1148.     MLDB        1092 1
  1149.     MLPR        1092 2
  1150.     ML1        1092 3
  1151.     MLOPC        1092 4
  1152.  
  1153.  O  /
  1154.   \/
  1155.   /\  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1156.  O  \
  1157.  
  1158.  
  1159.                         -- Jan Brittenson
  1160.                            bson@ai.mit.edu
  1161.